package cn.ivast.recyclerviewtest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

/**
 * RecyclerView相关学习
 */
public class MainActivity extends AppCompatActivity {

    public static final String url1 = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543140604386&di=1027e9678e0133cda11263591c31d14a&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F54ebececeda0217648263cc944d6cfd413a17cdf2cc6-MGHS0y_fw658";
    public static final String url2 = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543206559235&di=c2a52beb6af677c9a802ff1b781922f7&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2Fd17ad2565b6418379b5e7a3393bab02514de0d8925ce-IDo8Q2_fw658";
    private ImageView imageView1;
    private ImageView imageView2;

    public static final String LEFT = "LEFT";
    public static final String TOP = "TOP";
    public static final String WIDTH = "WIDTH";
    public static final String HEIGHT = "HEIGHT";
    public static final String INDEX = "INDEX";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, TanTanActivity.class);
                startActivity(intent);
            }
        });

        findViewById(R.id.btn2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainActivity.this, MyDecorationActivity.class);
                startActivity(i);
            }
        });

        findViewById(R.id.btn3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainActivity.this, StickyActivity.class);
                startActivity(i);
            }
        });

        findViewById(R.id.btn4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(MainActivity.this, ViewPagerActivity.class);
                startActivity(i);
            }
        });

        imageView1 = findViewById(R.id.imageView1);
        imageView2 = findViewById(R.id.imageView2);

        Glide.with(this).load(url1).into(imageView1);
        Glide.with(this).load(url2).into(imageView2);

        imageView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ViewPagerActivity.class);
                int[] screenLocation = new int[2];
                imageView1.getLocationOnScreen(screenLocation);
                //传递动画初始位置以及imageview图片路径过去
                intent.putExtra(LEFT, screenLocation[0]).
                        putExtra(TOP, screenLocation[1]).
                        putExtra(WIDTH, imageView1.getWidth()).
                        putExtra(HEIGHT, imageView1.getHeight()).
                        putExtra(INDEX, 0);
                startActivity(intent);
                //取消activity动画
                overridePendingTransition(0, 0);
            }
        });

        imageView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ViewPagerActivity.class);
                int[] screenLocation = new int[2];
                imageView2.getLocationOnScreen(screenLocation);
                //传递动画初始位置以及imageview图片路径过去
                intent.putExtra(LEFT, screenLocation[0]).
                        putExtra(TOP, screenLocation[1]).
                        putExtra(WIDTH, imageView2.getWidth()).
                        putExtra(HEIGHT, imageView2.getHeight()).
                        putExtra(INDEX, 1);
                startActivity(intent);
                //取消activity动画
                overridePendingTransition(0, 0);
            }
        });

    }
}
